package com.mpp.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mpp.common.exception.MyServiceException;
import com.mpp.common.result.ResultCodeEnum;
import com.mpp.hosp.mapper.HospitalSetMapper;
import com.mpp.hosp.service.HospitalSetService;
import com.mpp.model.entity.hosp.HospitalSet;
import com.mpp.model.vo.order.SignInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author MMDZ
 * @date 2022/8/16 10:14
 * @description TODO
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {

    @Autowired
    private HospitalSetMapper hospitalSetMapper;

    // 根据传递过来医院编码，查询数据库 签名
    @Override
    public String getSignKey(String hoscode) {
        HospitalSet hospitalSet = baseMapper.selectOne(new QueryWrapper<HospitalSet>().eq("hoscode", hoscode));
        if (Objects.isNull(hospitalSet))
            throw new MyServiceException(ResultCodeEnum.DATA_ERROR);
        return hospitalSet.getSignKey();
    }

    // 获取医院签名信息
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        HospitalSet hospitalSet = baseMapper.selectOne(new QueryWrapper<HospitalSet>().eq("hoscode", hoscode));
        if (Objects.isNull(hospitalSet))
            throw new MyServiceException(ResultCodeEnum.HOSPITAL_OPEN);
        return new SignInfoVo(hospitalSet.getApiUrl(), hospitalSet.getSignKey());
    }
}
